package com.ioudi.digu.flex.message.adapters;

import com.ioudi.digu.revise.IMessageRevisor;
import com.ioudi.digu.service.IMessageService;

import flex.messaging.messages.AcknowledgeMessage;
import flex.messaging.messages.Message;
import flex.messaging.services.messaging.adapters.ActionScriptAdapter;

public class MessageAdapter extends ActionScriptAdapter
{
	private IMessageService messageService;
	
	private IMessageRevisor messageRevisor;


	public Object invoke(Message message)
    {
		message = (Message)message.clone();
		boolean saved = messageService.createItem(message) != null;
		if(saved)
		{
			  super.invoke(message);
			  AcknowledgeMessage ack = new AcknowledgeMessage();
			  ack.setBody(messageRevisor.outboudRevise(message));
			  return ack;
		}
        return null;
    }
	
	public IMessageRevisor getMessageRevisor()
	{
		return messageRevisor;
	}

	public void setMessageRevisor(IMessageRevisor messageRevisor)
	{
		this.messageRevisor = messageRevisor;
	}
	
	public IMessageService getMessageService()
	{
		return messageService;
	}

	public void setMessageService(IMessageService messageService)
	{
		this.messageService = messageService;
	}
}
